//
//  ByNoticeBallCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/16.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByNoticeBallCell.h"

#import "ByNoticeBallResultView.h"
#import "ByDocumentaryFiveValue.h"
#import "ByDocumentaryFourValue.h"


@implementation ByNoticeBallCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByNoticeBallCell";
    ByNoticeBallCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    ByNoticeTitleView *titleView = [[ByNoticeTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(15);
        make.height.mas_equalTo(@15);
    }];
    
    if (_netModel.category_id.integerValue == 3010) {
        titleView.titleLabel.text = @"竞彩足球";
    }else if (_netModel.category_id.integerValue == 3001){
        titleView.titleLabel.text = @"竞彩蓝球";
    }
    titleView.timeLabel.text = [NSString stringWithFormat:@"%@ %@", _netModel.num ,_netModel.open_time];
    
    ByNoticeBallResultView *resultView = [[ByNoticeBallResultView alloc] init];
    [backgroundView addSubview:resultView];
    [resultView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(titleView.mas_bottom).offset(5);
        make.right.equalTo(backgroundView).offset(-40);
        make.height.mas_equalTo(@60);
    }];
    resultView.netModel = _netModel;
  
    
    UIImageView *arrowView = [[UIImageView alloc] init];
    [backgroundView addSubview:arrowView];
    [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-15);
        make.top.equalTo(backgroundView).offset(37);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    arrowView.image = [UIImage imageNamed:@"youjiantou1111"];
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = BY_LINE_COLOR;
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(resultView.mas_bottom).offset(0);
        make.height.mas_equalTo(@1);
    }];
    
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_bottom).offset(0);
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.bottom.equalTo(backgroundView).offset(0);
    }];
    grayView.backgroundColor = rgba(251, 251, 251, 1);
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [grayView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(grayView).offset(11);
        make.right.equalTo(grayView).offset(0);
        make.top.equalTo(grayView).offset(10);
        make.height.mas_equalTo(@15);
    }];
    titleLabel.font = FONT(14);
    titleLabel.textColor = [UIColor brownColor];
    titleLabel.text = @"开奖结果";
    
    
    if (_netModel.category_id.integerValue == 3010) {
        
        ByDocumentaryFiveValue *titleView1 = [[ByDocumentaryFiveValue alloc] initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH - 10, 30)];
        [grayView addSubview:titleView1];
        titleView1.valueLabel1.text = @"胜平负";
        titleView1.valueLabel2.text = @"让球";
        titleView1.valueLabel3.text = @"比分";
        titleView1.valueLabel4.text = @"总进球";
        titleView1.valueLabel5.text = @"半全场";
        
        ByDocumentaryFiveValue *valueView = [[ByDocumentaryFiveValue alloc] initWithFrame:CGRectMake(0, titleView1.bottom, SCREEN_WIDTH - 10, 30)];
        [grayView addSubview:valueView];
        valueView.valueLabel1.text = _netModel.jieguo;
        valueView.valueLabel3.text = _netModel.final_score;
        valueView.valueLabel4.text = [NSString stringWithFormat:@"%@",_netModel.zong];
        valueView.valueLabel5.text = _netModel.banquan;
        if (_netModel.let_score.integerValue < 0) {
            valueView.valueLabel2.text = [NSString stringWithFormat:@"(%@)主负",_netModel.let_score];
        }else if (_netModel.let_score.integerValue > 0){
            valueView.valueLabel2.text = [NSString stringWithFormat:@"(%@)主胜",_netModel.let_score];
        }else{
            valueView.valueLabel2.text = @"平";
        }
        valueView.valueLabel1.textColor = [UIColor redColor];
        valueView.valueLabel2.textColor = [UIColor redColor];
        valueView.valueLabel3.textColor = [UIColor redColor];
        valueView.valueLabel4.textColor = [UIColor redColor];
        valueView.valueLabel5.textColor = [UIColor redColor];
    }else{
        
        
        
        ByDocumentaryFourValue *titleView1 = [[ByDocumentaryFourValue alloc] initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH - 10, 30)];
        [grayView addSubview:titleView1];
        titleView1.valueLabel1.text = @"胜负";
        titleView1.valueLabel2.text = @"让分";
        titleView1.valueLabel3.text = @"大小分";
        titleView1.valueLabel4.text = @"胜负差";

        
        ByDocumentaryFourValue *valueView = [[ByDocumentaryFourValue alloc] initWithFrame:CGRectMake(0, titleView1.bottom, SCREEN_WIDTH - 10, 30)];
        [grayView addSubview:valueView];
        valueView.valueLabel1.text = _netModel.win;
        valueView.valueLabel3.text = [NSString stringWithFormat:@"%@", _netModel.zong];
        valueView.valueLabel4.text = [NSString stringWithFormat:@"%@",_netModel.victory];
        valueView.valueLabel2.text = [NSString stringWithFormat:@"%@",_netModel.let_score];
       
        valueView.valueLabel1.textColor = [UIColor redColor];
        valueView.valueLabel2.textColor = [UIColor redColor];
        valueView.valueLabel3.textColor = [UIColor redColor];
        valueView.valueLabel4.textColor = [UIColor redColor];
    }
    
    
   
    
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self initViews];
}

@end
